<template>
  <div class="shelf-item-category">
    <!-- 如果存在data.itemList则显示这个 -->
    <div class="shelf-item-category-list" v-if="data.itemList.length > 0">
      <div
        class="shelf-item-category-item"
        v-for="(item, index) in data.itemList"
        :key="index"
      >
        <img class="shelf-item-category-img" :src="item.cover" />
      </div>
    </div>

    <div class="shelf-item-category-bg" v-else>
      <span class="icon-book2"></span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    data: Object,
  },
  mounted() {
    // !data的数据结构
    //     {
    //     "id": 8,
    //     "itemList": [
    //         {
    //             "id": 1,
    //             "fileName": "2018_Book_HigherEducationInTheEraOfTheFo",
    //             "cover": "http://47.99.166.157/book/res/img//Education/978-981-13-0194-0_CoverFigure.jpg",
    //             "title": "Higher Education in the Era of the Fourth Industrial Revolution",
    //             "author": "Nancy W. Gleason",
    //             "publisher": "Springer Singapore",
    //             "bookId": "2018_Book_HigherEducationInTheEraOfTheFo",
    //             "category": 4,
    //             "categoryText": "Education",
    //             "language": "en",
    //             "rootFile": "OEBPS/package.opf",
    //             "selected": false,
    //             "private": false,
    //             "cache": false,
    //             "haveRead": 0,
    //             "type": 1
    //         }
    //     ],
    //     "selected": false,
    //     "title": "education",
    //     "type": 2
    // }
  },
};
</script>

<style scoped lang="scss">
@import '../../assets/styles/global';
.shelf-item-category {
  width: 100%;
  height: 100%;
  overflow: hidden;
  .shelf-item-category-list {
    display: flex;
    flex-flow: row wrap;
    align-content: flex-start;
    width: 100%;
    height: 100%;
    padding-top: px2rem(5);
    box-sizing: border-box;
    .shelf-item-category-item {
      flex: 0 0 33.3%;
      width: 33.3%;
      height: 33.3%;
      box-sizing: border-box;
      &:nth-child(3n + 1) {
        padding: 0 px2rem(2.5) px2rem(5) px2rem(5);
      }
      &:nth-child(3n + 2) {
        padding: 0 px2rem(2.5) px2rem(5) px2rem(2.5);
      }
      &:nth-child(3n + 3) {
        padding: 0 px2rem(5) px2rem(5) px2rem(2.5);
      }

      .shelf-item-category-img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .shelf-item-category-bg {
    width: 100%;
    height: 100%;
    background: #fff;
    font-size: px2rem(30);
    color: #ccc;
    @include center;
  }
}
</style>
